package com.bjtu.literatureclient.feign;

import com.bjtu.literatureclient.api.vo.request.UserIndexNoQueryTypeRequest;
import com.bjtu.literatureclient.base.result.Result;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author caiyuli
 * @date 2020/4/24 3:50 下午
 */

@FeignClient(value = "transactionclient", fallbackFactory = IndexNoFeignService.HystrixClientFallbackFactory.class)
public interface IndexNoFeignService {

    @RequestMapping(value = "/indexNo/query", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    Result queryEntity(UserIndexNoQueryTypeRequest request);



    @Component
    static class HystrixClientFallbackFactory implements FallbackFactory<IndexNoFeignService> {

        @Override
        public IndexNoFeignService create(Throwable throwable) {
            return new IndexNoFeignService() {
                @Override
                public Result queryEntity(UserIndexNoQueryTypeRequest request) {
                    return Result.fail(-1,"服务调用失败");
                }
            };
        }
    }



}
